# Create your views here.
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext 
from lab.books.models import Book, BookForm


def book_form(request, id=None):
    book = None
    if id is not None:
        book = Book.objects.get(id=id)
    if request.POST:
        form = BookForm(data=request.POST, instance=book)
        if form.is_valid():
       	 	new_book.save()
        #	form.save_m2m()
        	return HttpResponseRedirect('/books/')
    else:
        form = BookForm(instance = book)
        
    return render_to_response('books/book_form.html',{'form':form},context_instance=RequestContext(request))

